package ControlLayer;
import ModelLayer.*;

/**
 * Controller class for the Borrow class.
 * 
 * @author Tue Brodersen
 * @version 1.0 (2013-11-07)
 */
public class BorrowCtr
{
    private static AddressCtr addrCtr;
    private static DVDCtr dvdCtr;
    private static BorrowCtr instance;
    
    /**
     * Constructor for the Borrow Controller
     */
    public BorrowCtr()
    {
        addrCtr = AddressCtr.getInstance();
        dvdCtr = DVDCtr.getInstance();
    }
    
    /**
     * A method to get the borrow controller instance
     * 
     * @return Returns the instance of Borrow Controller of type object(BorrowCtr)
     */
    public static BorrowCtr getInstance()
    {
        if(instance == null)
        {
            instance = new BorrowCtr();
        }
        
        return instance;
    }
    
    /**
     * A method to get a person object
     * 
     * @param id Inputs the ID of the person of type long
     * @return Returns the Person of type object(Person)
     */
    public Person getPerson(long id)
    {
        return addrCtr.getPerson(id);
    }
    
        
    /**
     * A method to create a Borrow object and add a specimen
     * 
     * @param dvdId the id of the Dvd
     * @param specimenId the id of the dDdSpecimen
     * @param personId the id of the Person
     */
    public void createLoan(long dvdId, long specimenId, long personId)
    {
        DvdSpecimen specimen = dvdCtr.findSpecimen(dvdId, specimenId);
        Borrow loan = new Borrow();
        loan.addSpecimen(specimen);
        specimen.setAvailable(false);
        addrCtr.getPerson(personId).addLoan(loan);
        
    }
    
    /**
     * A method to see whether a DvdSpecimen is avaiable or not
     * 
     * @param dvdId the id of the Dvd
     * @param specimenId the id of the dDdSpecimen
     * 
     * @return true or false
     */
    public boolean isSpecimenAvailable(long dvdId, long specimenId)
    {
        DvdSpecimen specimen = dvdCtr.findSpecimen(dvdId, specimenId);
        return specimen.getAvailable();
    }
}
